﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Serializer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            User user = new User();
            user.UserName = this.textBox1.Text;
            user.Password = this.textBox2.Text;

            byte[] buf = SerializeBinary.ObjectToByte(user);;
            string s = "";
            for (int i = 0; i < buf.Length; i++)
            {
                s = s + buf[i].ToString() + "|";
            }

            this.textBox3.Text = s;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string[] s = this.textBox3.Text.Trim().Split('|');
            byte[] buf = new byte[s.Length];
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] != "")
                {
                    buf[i] = Convert.ToByte(s[i]);
                }
            }
            User user = SerializeBinary.BtyeToObject<User>(buf);

            this.textBox5.Text = user.UserName;
            this.textBox4.Text = user.Password;

        }
    }
}
